package com.cskaoyan.controller.wx.service;

import com.cskaoyan.bean.bo.PageCommonParamBo;
import com.cskaoyan.bean.entity.Footprint;
import com.cskaoyan.bean.entity.FootprintExample;
import com.cskaoyan.bean.vo.BasePageData;
import com.cskaoyan.mapper.FootprintMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <h1> FootprintServiceImpl </h1>
 * Created by GaoJia
 * Date  2021/10/22 14:48
 */
@Service
public class FootprintServiceImpl implements FootprintService {
    @Autowired
    FootprintMapper footprintMapper;

    @Override
    public BasePageData<Footprint> list(PageCommonParamBo pageParam) {

        // 创建 排序 返回
        FootprintExample footprintExample = new FootprintExample();
        footprintExample.setOrderByClause("`id` desc");
        List<Footprint> footprints = footprintMapper.selectByExample(footprintExample);
        return BasePageData.ok(footprints);
    }

    @Override
    public int delete(Integer id) {
        // TODO 暂时完成
        footprintMapper.deleteByPrimaryKey(id);
        return 0;
    }

    @Override
    public Integer getNewestGoodsIdByUserId(Integer userId) {
        Integer[] goodsIds = footprintMapper.selectGoodsIdByUserId(userId);
        return goodsIds[goodsIds.length - 1];
    }
}
